package com.meilele.dao.shiro;

import com.meilele.entity.shiro.User;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

@Repository
public interface UserMapper {
    @Delete({
        "delete from users",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    @Insert({
        "insert into users (id, username, ",
        "password, user_tel, ",
        "user_solt, user_nikine, ",
        "truename, user_city, ",
        "user_qq, user_email, ",
        "user_autograph)",
        "values (#{id,jdbcType=INTEGER}, #{username,jdbcType=VARCHAR}, ",
        "#{password,jdbcType=VARCHAR}, #{userTel,jdbcType=CHAR}, ",
        "#{userSolt,jdbcType=VARCHAR}, #{userNikine,jdbcType=VARCHAR}, ",
        "#{truename,jdbcType=VARCHAR}, #{userCity,jdbcType=VARCHAR}, ",
        "#{userQq,jdbcType=CHAR}, #{userEmail,jdbcType=VARCHAR}, ",
        "#{userAutograph,jdbcType=VARCHAR})"
    })
    int insert(User record);

    int insertSelective(User record);

    @Select({
        "select",
        "id, username, password, user_tel, user_solt, user_nikine, truename, user_city, ",
        "user_qq, user_email, user_autograph",
        "from users",
        "where id = #{id,jdbcType=INTEGER}"
    })
    @ResultMap("com.meilele.dao.shiro.UserMapper.BaseResultMap")
    User selectByPrimaryKey(Integer id);

    int updateByPrimaryKeySelective(User record);

    @Update({
        "update users",
        "set username = #{username,jdbcType=VARCHAR},",
          "password = #{password,jdbcType=VARCHAR},",
          "user_tel = #{userTel,jdbcType=CHAR},",
          "user_solt = #{userSolt,jdbcType=VARCHAR},",
          "user_nikine = #{userNikine,jdbcType=VARCHAR},",
          "truename = #{truename,jdbcType=VARCHAR},",
          "user_city = #{userCity,jdbcType=VARCHAR},",
          "user_qq = #{userQq,jdbcType=CHAR},",
          "user_email = #{userEmail,jdbcType=VARCHAR},",
          "user_autograph = #{userAutograph,jdbcType=VARCHAR}",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(User record);
    @Select({
            "select",
            "id, username, password, user_tel, user_solt, user_nikine, truename, user_city, ",
            "user_qq, user_email, user_autograph",
            "from users",
            "where username = #{username,jdbcType=INTEGER}"
    })
    @ResultMap("com.meilele.dao.shiro.UserMapper.BaseResultMap")
    User findByUsernameAndPassword(String username);
}